from django.views import View
# 导入redis
from SaaSDevelTool.data_redis_link import r
# 导入返回响应
from SaaSDevelTool.data_return_response import create_response
# 导入错误信息装饰器
from SaaSDevelTool.data_return_response import error_message_detection

"""
用户退出登录
"""


class SaaSDevelUserOutLogin(View):
    @error_message_detection
    def post(self, request):
        # 如果不存在获取token
        try:
            # 获取token
            token = request.headers["Token"]
        except Exception as err:
            # 返回对应的报错信息
            return create_response(code=401, msg="无权访问必须携带token", data="")

        # 删除对应的回话保持
        r.del_str(1, f"background_token{token}")
        # 返回对应的响应
        return create_response(code=200, msg="退出登录成功。")
